package com.sghd.candy.module.skill.manager;

import com.sghd.common.ramcache.IEntity;
import com.sghd.common.ramcache.PerPersist;
import com.sghd.common.ramcache.anno.*;
import com.sghd.common.utils.json.JsonUtils;

import javax.persistence.*;
import java.util.Map;

/**
 * @author Allen
 * @date 2018/12/07
 */
@Entity
@Table(catalog = "bsdld")
@Cached(size = CachedSizes.DEFAULT, persister = @Persister(Persisters.PRE_HOUR))
@InitialConfig(type = InitialType.ALL)
public class SkillConfig implements IEntity<Integer>, PerPersist {
    @Id
    private Integer skillId;
    @Column(length = 10)
    private String skillName;
    /**技能稀有度*/
    private Integer rarity;
    /**分解技能获得的碎片*/
    private Integer discount;

    /**升级配置*/
    @Transient
    private Map<Integer, UpgradeSkill> upgradeConfig;
    @Lob
    private String upgradeConfigJson;

    public Integer getSkillId() {
        return skillId;
    }

    void setSkillId(Integer skillId) {
        this.skillId = skillId;
    }

    public String getSkillName() {
        return skillName;
    }

    void setSkillName(String skillName) {
        this.skillName = skillName;
    }

    public Integer getRarity() {
        return rarity;
    }

    void setRarity(Integer rarity) {
        this.rarity = rarity;
    }

    public Integer getDiscount() {
        return discount;
    }

    void setDiscount(Integer discount) {
        this.discount = discount;
    }

    public Map<Integer, UpgradeSkill> getUpgradeConfig() {
        return upgradeConfig;
    }

    void setUpgradeConfig(Map<Integer, UpgradeSkill> upgradeConfig) {
        this.upgradeConfig = upgradeConfig;
    }

    public String getUpgradeConfigJson() {
        return upgradeConfigJson;
    }

    void setUpgradeConfigJson(String upgradeConfigJson) {
        this.upgradeConfigJson = upgradeConfigJson;
    }

    @Override
    public Integer getId() {
        return this.skillId;
    }

    @Override
    public void afterLoad() {
        upgradeConfig = JsonUtils.string2Map(upgradeConfigJson, Integer.class, UpgradeSkill.class);
    }

    @Override
    public void beforePersist() {
        upgradeConfigJson = JsonUtils.object2String(upgradeConfig);
    }
}
